package com.ews.onlineexchange.model;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.PostLoad;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import org.apache.lucene.analysis.cn.smart.SmartChineseAnalyzer;
import org.hibernate.search.annotations.Analyzer;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;

import com.ews.onlineexchange.util.SystemUUIDUtil;

@Entity
@Indexed
public class AgentService extends DataEntity {
	/**
	 * 
	 */
	private static final long	serialVersionUID	= 1L;
	
	private String				name;
	private QualificationClass	qualificationClass;
	private String 				serviceIndex;

	@NotNull
	@Field(analyzer = @Analyzer(impl = SmartChineseAnalyzer.class))
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@ManyToOne
	public QualificationClass getQualificationClass() {
		return qualificationClass;
	}

	public void setQualificationClass(QualificationClass qualificationClass) {
		this.qualificationClass = qualificationClass;
	}
	
	@PostLoad
	private void postLoad() {
		this.setHighLightTitle(this.getName());	
		this.setServiceIndex(SystemUUIDUtil.getUUID());
	}
	
	@Transient
	public String getServiceIndex() {
		return serviceIndex;
	}

	public void setServiceIndex(String serviceIndex) {
		this.serviceIndex = serviceIndex;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((qualificationClass == null) ? 0 : qualificationClass.hashCode());
		result = prime * result + ((serviceIndex == null) ? 0 : serviceIndex.hashCode());
		return result;
	}

	

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		AgentService other = (AgentService) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (qualificationClass == null) {
			if (other.qualificationClass != null)
				return false;
		} else if (!qualificationClass.equals(other.qualificationClass))
			return false;
		if (serviceIndex != other.serviceIndex)
			return false;
		return true;
	}

	
}
